/*
 * Developer : Jack Matthews
 * Email: developer@droidprofessor.com
 * 
 * Copyright (C) 2010 http://droidprofessor.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.droidprofessor.android.library.phonelicenses;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.droidprofessor.android.library.phonelicenses.R;

import android.content.Context;
import android.widget.Toast;

/**
 * Helper class for validating user input
 * 
 * @author Jack Matthews (jackmatt2@gmail.com)
 *
 */
class ValidationHelper {
	
	private ValidationHelper(){};
	
	/**
	 * Validate a username
	 * @param cnx
	 * @param username
	 * @return
	 */
	static boolean validateUsername(Context cnx, String username) {
		//Check username
		if(username.equals("")) {
			Toast.makeText(cnx, R.string.com_phonelicenses_bad_username ,Toast.LENGTH_LONG).show();
			return false;
		}
		return true;
	}
	
	
	/**
	 * Validate a password
	 * 
	 * @param cnx
	 * @param password
	 * @return
	 */
	static boolean validatePassword(Context cnx, String password) {
		//Check username
		if(password.length() < 6) {
			Toast.makeText(cnx, R.string.com_phonelicenses_bad_password ,Toast.LENGTH_LONG).show();
			return false;
		}
		
		return true;
	}
	
	
	/**
	 * Validate an email address
	 * @param cnx
	 * @param email
	 * @return
	 */
	static boolean validateEmailAddress(Context cnx, String email) {
		//check email address
	    Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
	    Matcher m = p.matcher(email);
	    boolean matchFound = m.matches();

	    if(!matchFound) {
			Toast.makeText(cnx, R.string.com_phonelicenses_bad_email ,Toast.LENGTH_LONG).show();   	
	    }
	    
		return matchFound;
	}

	
	
	/**
	 * Validate a name
	 * @param cnx
	 * @param name
	 * @return
	 */
	static boolean validateName(Context cnx, String name) {
		//Check username
		if(name.equals("")) {
			Toast.makeText(cnx, R.string.com_phonelicenses_bad_name ,Toast.LENGTH_LONG).show();
			return false;
		}
		return true;
	}
	
}
